package dse.messages.multiversion;

import dse.Experiment;
import dse.ExperimentRecorder;
import dse.messages.Message;
import dse.messages.MessageHandler;
import dse.messages.MessageSender;
import dse.messages.MessageType;

public class VersionResponseV3MessageHandler extends MessageSender implements
		MessageHandler {
	private VersionReader reader;
	private int sequence;
	
	public VersionResponseV3MessageHandler (
			Experiment experiment, 
			int sequence,
			VersionReader reader
			)
	{
		super(experiment);
		
		this.sequence = sequence;
		this.reader = reader;
	}

	
	@Override
	public boolean acceptMessage(Message message) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void messageInterupted(ExperimentRecorder recorder, Message message,
			double timeLeft) {
		// TODO Auto-generated method stub
		recorder.debug(this, "msgIntrpt: " + message, timeLeft);
		reader.readVersion(recorder, -1, timeLeft);
	}

	@Override
	public void messageReceived(ExperimentRecorder recorder, Message message,
			double timeLeft) {
		// TODO Auto-generated method stub
		recorder.debug(this, "msgRcvd: " + message, timeLeft);
		if (message.messageType() != MessageType.VersionResponseV3) {
			recorder.warn(
					"VersionResponseV3MessageHandler recieved " + 
					message.messageType() + " message."
					);
			return;
		}
		
		reader.readVersion(recorder, sequence, timeLeft);
	}
}
